<template>
  <div id="app" @touchstart="closeMenu">
    <transition name="router-fade" mode="out-in">
      <keep-alive v-if="$route.meta.keepAlive">
        <router-view></router-view>
      </keep-alive>
    </transition>
    <transition name="router-fade" mode="out-in">
      <router-view v-if="!$route.meta.keepAlive"></router-view>
    </transition>
    <transition name="mask">
      <div @touchstart.stop.prevent="()=>{}" class="mask" @click="clickHideMask" v-if="maskIsShow"></div>
    </transition>
  </div>
</template>

<script>
import {getQueryVariable, judgeEquipment} from '@/tools/utils'
import { mapState } from "vuex";
export default {
  name: "App",
  data() {
    return {};
  },
  created() {
    this.$store.commit('SAVE_REQUEST_PARAMS', {
      token: getQueryVariable('token') || this.$store.state.token,
      unionKey: getQueryVariable('unionKey') || this.$store.state.unionKey,
      platform: getQueryVariable('platform') || this.$store.state.platform
    })
    this.$store.commit('GET_DEVICE_ENV', {
      deviceEnvironment: judgeEquipment()
    })
  },
  watch: {
    '$store.state.serverTime' (val) {
      this.$store.commit("JUDGE_CURRENT_TIME_STATE");
    }
  },
  computed: mapState({
    maskIsShow: state => {
      return state.maskIsShow;
    },
    showOption: state => {
      return state.showOption;
    },
  }),
  methods: {
    closeMenu (event) {
      if (event.target.classList.contains('dot')) {
        return
      }
      if (this.showOption) {
        this.$store.commit('CLOSE_MENU', {
          showOption: false
        })
      }
    },
    clickHideMask() {
      // this.$store.commit("controlMask", { maskIsShow: false });
    }
  }
};
</script>
<style lang="less" scoped>
#app {
  font-family: sans-serif, "Avenir", Helvetica, Arial;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  moz-user-select: -moz-none;
  -moz-user-select: none;
  -o-user-select:none;
  -khtml-user-select:none;
  -webkit-user-select:none;
  -ms-user-select:none;
  user-select:none;

  .bounce-enter-active {
    animation: bounce-in .5s;
  }
  .bounce-leave-active {
    animation: bounce-in .5s reverse;
  }
  @keyframes bounce-in {
    0% {
      transform: scale(0);
    }
    50% {
      transform: scale(1.5);
    }
    100% {
      transform: scale(1);
    }
  }
  .mask {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 99;
    background: rgba(0, 0, 0, 0.8);
  }
  .mask-enter-active,
  .mask-leave-active {
    transition: opacity 0.5s;
  }
  .mask-enter,
  .mask-leave-to {
    opacity: 0;
  }
}
</style>